﻿using System;
using System.Windows;
using System.Windows.Controls;

using Hetymine.Executioner.Data;
using Hetymine.Executioner.Triggers;

namespace Hetymine.Executioner.Plugins.Triggers.Speech {
    /// <summary>
    /// Interaction logic for SpeechTriggerConfigurator.xaml
    /// </summary>
    public partial class SpeechTriggerConfigurator : UserControl, IConfigurator<ITrigger> {        
        private SpeechTrigger _Trigger;
        private bool _IsApply = true;

        public SpeechTriggerConfigurator() {
            InitializeComponent();

            this.cPhrase.TextChanged += new TextChangedEventHandler(Phrase_TextChanged);
            this.cSelected.Click += new RoutedEventHandler(Selected_Click);
        }

        #region Control Events
        private void Phrase_TextChanged(object sender, TextChangedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Trigger.Phrase = this.cPhrase.Text;

            //this.OnCommandNameChanged(this, EventArgs.Empty);
        }
        private void Selected_Click(object sender, RoutedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Trigger.IsSelected = this.cSelected.IsChecked.Value;
        }
        #endregion

        #region IConfigurator<ITrigger> Members
        public void InitializeConfig(ITrigger config) {
            this._Trigger = config as SpeechTrigger;

            this._IsApply = false;

            this.cPhrase.Text = this._Trigger.Phrase;
            this.cSelected.IsChecked = false;

            this._IsApply = true;
        }
        public UserControl ConfigPanel { get { return this; } }

        //public event CommandNameEventHandler CommandNameChanged;
        //protected virtual void OnCommandNameChanged(object sender, EventArgs e) {
        //    if (this.CommandNameChanged != null) {
        //        this.CommandNameChanged(sender, e);
        //    }
        //}
        #endregion
    }
}
